//Team: T102-17 
//Members: wrr3hw/ William Rinaldi; atb3df/ Austin Beane; cea7dz/ Katie Aichholz; jpp7mt/Jessica Platter

package cs2110.virginia.edu.ghosthunter;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;

public class StartScreen extends Activity implements OnClickListener {

	MediaPlayer splashMusic;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		setContentView(R.layout.splash);
		
		Thread playMusic = new Thread() {
			public void run() {
			splashMusic = MediaPlayer.create(StartScreen.this, R.raw.splashthemesong);
			splashMusic.start();
			splashMusic.setLooping(true);
			}
		};
		playMusic.run();
	
		
		Thread startButtonClicked = new Thread() {
//		public void run() {
//    		try {
//    			sleep(5000);
//    			Intent mainGameIntent = new Intent("cs2110.virginia.edu.ghosthunter.MAINGAME");
//    			startActivity(mainGameIntent);
//    			
//    		} catch (InterruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//    		
//    		finally {
//    			finish();
//    		}
//    	}
    };
    startButtonClicked.start();
	}
	

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		splashMusic.start();
		
	}
	
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		splashMusic.stop();
	}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
	}
	public void startgame(View view){
		Intent mainGameIntent = new Intent("cs2110.virginia.edu.ghosthunter.MAINGAME");
		startActivity(mainGameIntent);
		splashMusic.release();
	}

}
